//
//  UILabel+Extension.swift
//  PGWeibo
//
//  Created by Apple on 15/11/5.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

extension UILabel {
    /// 便利构造函数
    ///
    /// - parameter title:          title
    /// - parameter fontSize:       fontSize，默认 14 号字
    /// - parameter color:          color，默认深灰色
    /// - parameter screenInset:    相对与屏幕左右的缩进，默认为0，局中显示，如果设置，则左对齐
    ///
    /// - returns: UILabel
    /// 参数后面的值是参数的默认值，如果不传递，就使用默认值
    convenience init(title: String, textFont: CGFloat = 14, color: UIColor = UIColor.darkGrayColor(), screenInset: CGFloat = 0) {
        self.init()
        text = title
        font = UIFont.systemFontOfSize(textFont)
        textColor = color
        numberOfLines = 0
        sizeToFit()
        
        if screenInset == 0 {
            textAlignment = .Center
        }else{
            textAlignment = .Left
            preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.width - 2 * screenInset
        }
    }
}
